package com.example.word.ui.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.dict.R;
import com.example.word.bean.User;
import com.example.word.util.HttpUtils;
import com.example.word.util.MessageUtils;
import com.example.word.widget.ActionBar;

import org.litepal.crud.DataSupport;

import java.util.HashMap;
import java.util.Map;

/**
 * 用户信息管理
 */
public class UserDetailActivity extends AppCompatActivity {
    private ActionBar mTitleBar;//标题栏
    private Activity mActivity;
    private TextView account, dict, dayTask, todayCount, reviewCount, totalCount, onlineText;
    private EditText nickName;
    private EditText phoneNumber;
    private User mUser;
    private Button btnSave;//保存
    private ImageView onlineImg, onlineImgYes;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_detail);
        mActivity = this;
        account = findViewById(R.id.account);
        dict = findViewById(R.id.dict);
        dayTask = findViewById(R.id.dayTask);
        todayCount = findViewById(R.id.todayCount);
        reviewCount = findViewById(R.id.reviewCount);
        totalCount = findViewById(R.id.totalCount);
        onlineText = findViewById(R.id.onlineText);
        onlineImg = findViewById(R.id.onlineImg);
        onlineImgYes = findViewById(R.id.onlineImgYes);
        // btnSave = findViewById(R.id.btn_save);
        mTitleBar = findViewById(R.id.myActionBar);
        //侧滑菜单
        mTitleBar.setData(mActivity, "详细信息", R.drawable.ic_back, R.drawable.a1, 0, getResources().getColor(R.color.colorPrimary), new ActionBar.ActionBarClickListener() {
            @Override
            public void onLeftClick() {
                finish();
            }

            @Override
            public void onRightClick() {
            }
        });
        // 设置主题
        // 设置主题
        if (!com.example.word.ui.activity.MainActivity.colorChange) {
            mTitleBar.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
        } else {
            mTitleBar.setBackgroundColor(getResources().getColor(R.color.myColor));
        }
        mUser = (User) getIntent().getSerializableExtra("user");
        if (mUser != null) {
            account.setText(mUser.getAccount() + " (" + mUser.getNickName() + ")");
            dict.setText(mUser.getStudyPlan().getDict());
            dayTask.setText(String.valueOf(mUser.getStudyPlan().getDayTask()));
            todayCount.setText(String.valueOf(mUser.getStudyPlan().getTodayCount()));
            reviewCount.setText(String.valueOf(mUser.getStudyPlan().getReviewCount()));
            totalCount.setText(String.valueOf(mUser.getStudyPlan().getTotalCount()));

            onlineImg.setVisibility(mUser.isOnline() ? View.GONE : View.VISIBLE);
            onlineImgYes.setVisibility(!mUser.isOnline() ? View.GONE : View.VISIBLE);
            onlineText.setText(mUser.isOnline() ? " 在线" : " 离线");
        }
    }

//    //保存
//    public void save(View view) {
//        String nickNameStr = nickName.getText().toString();
//        String phoneStr = phoneNumber.getText().toString();
//        if ("".equals(nickNameStr)) {
//            Toast.makeText(mActivity, "昵称不能为空", Toast.LENGTH_SHORT).show();
//            return;
//        }
//        if ("".equals(phoneStr)) {
//            Toast.makeText(mActivity, "电话不能为空", Toast.LENGTH_SHORT).show();
//            return;
//        }
//        Map<String, String> requestParam = new HashMap<>();
//        requestParam.put("account", mUser.getAccount());
//        requestParam.put("nickName", nickNameStr);
//        requestParam.put("phoneNumber", phoneStr);
//        // 调用 API 客户端的方法
//        HttpUtils.sendGetRequest("/userInfoUpdate", requestParam, mActivity, Object.class, response -> {
//            MessageUtils.show("保存成功！", mActivity);
//            finish();//关闭页面
//        });
//
//    }
}
